const express = require('express')
const path = require('path');
const app = express();
const superagent = require('superagent');
const port = 8000

app.use(express.static('views'))
app.use(express.static(path.join(__dirname, 'public')))
// app.use(express.static('s'))
// app.use(express.static('views'))
// app.use(express.static('views'))

app.get('/', (req, res) => res.send(__dirname + '/views/index.html'))

app.get('/wx/authorize', async (req, res) => {
  const {query} = req;
  const redirect_uri = query.redirect_uri;
  const AppSecret = '99f5afdc781f32b7a6c77e40f628985f';
  const Appid = 'wx6faabee0fed31263'
  const _res = await superagent.get(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${Appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`);
  console.log(_res);
  //https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx520c15f417810387&redirect_uri=https%3A%2F%2Fchong.qq.com%2Fphp%2Findex.php%3Fd%3D%26c%3DwxAdapter%26m%3DmobileDeal%26showwxpaytitle%3D1%26vb2ctag%3D4_2030_5_1194_60&response_type=code&scope=snsapi_base&state=123#wechat_redirect
  
  res.send(_res.text);
  
})

// app.listen(port, () => console.log(`Example app listening on port ${port}!`))

app.listen(port, '0.0.0.0', function() {
  console.log(`Example app listening on port ${port}!`);
});